package com.lyj.mode.strategy;

/**
 * 制作蛋糕枚举
 * @author:liyajie
 * @createTime:2022/2/24 10:57
 * @version:1.0
 */
public enum CakeEnum {
    APPLE(AppleCakeHandler.class.getSimpleName(),new AppleCakeHandler()),
    BANANA(BananaCakeHandler.class.getSimpleName(),new BananaCakeHandler());

    private final String cakeType;
    private final CakeHandler cakeHandler;
    CakeEnum(String cakeType, CakeHandler cakeHandler){
        this.cakeType = cakeType;
        this.cakeHandler = cakeHandler;
    }

    // 匹配策略类
    public static CakeEnum match(String cakeType){
        CakeEnum[] values = CakeEnum.values();
        for (CakeEnum cakeEnum : values) {
            if(cakeType.equals(cakeEnum.cakeType)){
                return cakeEnum;
            }
        }
        return null;
    }

    public String getCakeType(){
        return cakeType;
    }

    public CakeHandler getCakeHandler(){
        return cakeHandler;
    }
}
